import { Command } from "../../Command/Command";
import { KeyMap } from "../../Enumerate/KeyMap";
import { IRegisterShortcut } from "../../Interface/ShortCut";

export const ShortCutList: IRegisterShortcut[] = [
  {
    key: KeyMap.S,
    ctrl: true,
    preventDefault: true,
    desc: "Ctrl + S 保存",
    callback: (command: Command) => command.executeSave(),
  },
  {
    key: KeyMap.Z,
    ctrl: true,
    desc: "Ctrl + Z 撤销",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command) => command.executeUndo(),
  },
  {
    key: KeyMap.Y,
    ctrl: true,
    desc: "Ctrl + Y 重做",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command) => command.executeRedo(),
  },
  {
    key: KeyMap.D,
    ctrl: true,
    preventDefault: true,
    desc: "Ctrl + D 删除当前幻灯片",
    callback: (command: Command) => command.executeDeleteSlide(),
  },
  {
    key: KeyMap.C,
    ctrl: true,
    stopPropagation: true,
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    desc: "Ctrl + C 复制当前元素",
    callback: (command: Command) => command.executeCopy(),
  },
  {
    key: KeyMap.V,
    ctrl: true,
    stopPropagation: true,
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    desc: "Ctrl + V 粘贴当前元素",
    callback: (command: Command) => command.executePaste(),
  },
  {
    key: KeyMap.X,
    ctrl: true,
    stopPropagation: true,
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    desc: "Ctrl + X 剪切当前元素",
    callback: (command: Command) => command.executeCut(),
  },
  {
    key: KeyMap.P,
    ctrl: true,
    preventDefault: true,
    desc: "Ctrl + P 打印当前画布",
    callback: (command: Command) => command.executePrint(),
  },
  {
    key: KeyMap.F2,
    desc: "F2 重命名当前文件",
    callback: (command: Command) => command.executeRename(),
  },
  {
    key: KeyMap.F5,
    ctrl: true,
    preventDefault: true,
    desc: "Ctrl + F5 预览当前画布",
    callback: (command: Command) => command.executePreviewCurrent(),
  },
  {
    key: KeyMap.F5,
    preventDefault: true,
    desc: "F5 从头放映当前画布",
    callback: (command: Command) => command.executePreviewBeginning(),
  },
  {
    key: KeyMap.M,
    ctrl: true,
    desc: "Ctrl + M 设置属性",
    callback: (command: Command) => command.executeOpenSetting(),
  },
  {
    key: KeyMap.Delete,
    desc: "delete 删除当前选中的图形",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command) => command.executeDeleteGraph(),
  },
  {
    key: KeyMap.Backspace,
    desc: "backspace 删除当前选中的图形",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command) => command.executeDeleteGraph(),
  },
  {
    key: KeyMap.Up,
    desc: "向上移动当前选中的图形/上一个幻灯片",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command, e?: Event) => command.executeMoveGraph(e!),
  },
  {
    key: KeyMap.Up,
    ctrl: true,
    desc: "向上移动当前选中的图形/上一个幻灯片",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command, e?: Event) => command.executeMoveGraph(e!),
  },
  {
    key: KeyMap.Down,
    desc: "向下移动当前选中的图形/下一个幻灯片",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command, e?: Event) => command.executeMoveGraph(e!),
  },
  {
    key: KeyMap.Down,
    ctrl: true,
    desc: "向下移动当前选中的图形/下一个幻灯片",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command, e?: Event) => command.executeMoveGraph(e!),
  },
  {
    key: KeyMap.Left,
    desc: "向左移动当前选中的图形/上一个幻灯片",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command, e?: Event) => command.executeMoveGraph(e!),
  },
  {
    key: KeyMap.Left,
    ctrl: true,
    desc: "向左移动当前选中的图形/上一个幻灯片",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command, e?: Event) => command.executeMoveGraph(e!),
  },
  {
    key: KeyMap.Right,
    desc: "向右移动当前选中的图形/下一个幻灯片",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command, e?: Event) => command.executeMoveGraph(e!),
  },
  {
    key: KeyMap.Right,
    ctrl: true,
    desc: "向右移动当前选中的图形/下一个幻灯片",
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    callback: (command: Command, e?: Event) => command.executeMoveGraph(e!),
  },
  {
    key: KeyMap.A,
    ctrl: true,
    stopPropagation: true,
    preventDefault: true,
    when: ({ e }) => <boolean>((<HTMLElement>e.target).nodeName === "BODY"),
    desc: "Ctrl + A 全选",
    callback: (command: Command) => command.executeSelectAll(),
  },
];
